<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的文章</title>
    <script src="jquery-1.9.1.min.js"></script>
    <script>
        //时间格式化
        function datefm(timespan) {
            var date = new Date(timespan);
            var y = date.getFullYear();//年
            var m = date.getMonth() + 1;//月//因为月份默认是上月的
            var d = date.getDate();
            return y + "-" + m + "-" + d;
        }

        //文章删除
        function mydel(id) {
            if (confirm("确认删除？")) {
                //删除
                jQuery.getJSON("mydel", {"id": id}, function (data) {
                    if (data != null && data.succ == 1) {
                        alert("删除成功！");
                        location.href = location.href;//刷新页面
                    } else {
                        alert("删除失败！" + data.msg);
                    }
                });
            }
        }

        jQuery(function () {
            jQuery.getJSON("myart", {}, function (data) {
                //将table信息替换为后台数据
                if (data != null && data.succ == 1) {
                    //成功
                    var html = "";
                    for (var i = 0; i < data.list.length; i++) {
                        var article = data.list[i];
                        html += " <tr>\n" +
                            "            <td>\n" +
                            article.id + "                \n" +
                            "            </td>\n" +
                            "            <td>\n<a href='detail.html?id=" + article.id + "'>" +
                            article.title + " </a>                 \n" +
                            "            </td>\n" +
                            "            <td>\n" +
                            datefm(article.createtime) + "                \n" +
                            "            </td>\n" +
                            "            <td>\n" +
                            datefm(article.updatetime) + "                \n" +
                            "            </td>\n" +
                            "            <td>\n" +
                            article.rcount + "                \n" +
                            "            </td>\n" +
                            "            <td>\n" +
                            "               <a href='upart.html?id=" + article.id +
                            "'>编辑</a> <a href='javascript:mydel(" + article.id + ")'>删除</a>\n" +
                            "            </td>\n" +
                            "        </tr>";
                    }
                    jQuery("#tab").append(html);//在被选元素的结尾（仍然在内部）插入指定内容
                } else {
                    alert("操作失败！" + data.msg);
                    location.href = "log.html";
                }
            });
        });
    </script>
</head>
<body style="background-image: url(b2.JPG);background-repeat: no-repeat;background-size: 100% auto">
<!--<body style="background: gainsboro">-->
<div style="margin-top: 50px;text-align: center;">
    <h1>我的文章</h1>

    <div style="text-align: center;font-size: larger;">
        <a href="addart.html">添加文章</a>
        <a href="list.html">分页查看所有文章</a>
        <a href="log.html">退出登录</a>
    </div>
    <hr>
    <p></p>
    <table id="tab" style="width:80%;margin: auto;" border="1"><!--border边框属性-->
        <tr><!--标签定义 HTML 表格中的行。-->
            <td><!--标签定义 HTML 表格中的标准单元格。-->
                编号
            </td>
            <td>
                标题
            </td>
            <td>
                发布时间
            </td>
            <td>
                修改时间
            </td>
            <td>
                阅读量
            </td>
            <td>
                操作
            </td>
        </tr>
    </table>
</div>
</body>
</html>